package com.iotteam.androidbase.commen.views.charts;

import android.graphics.Canvas;
import android.graphics.Paint;

import java.util.List;

/**
 * Created by vonchenchen on 14/08/2017.
 */

public class AxisRenderer extends AbsRenderer {

    private Axis mAxis;
    private Canvas mCanvas;

    public Paint mHorizantalBaseLinePaint;
    public Paint mVerticalBaseLinePaint;

    public Paint mTextPaint;

    public Paint mHorizantalPaint;
    public Paint mVerticalPaint;

    public AxisRenderer(Axis axis) {
        mAxis = axis;
    }

    public void render(Canvas canvas){
        mCanvas = canvas;
        drawAxis();
        drawLines();
    }

    /**
     * 绘制轴线
     */
    private void drawAxis(){

        Point baseLineStartPoint = mAxis.getBaseLineStartPoint();
        Point baseLineStopPoint = mAxis.getBaseLineStopPoint();

        if(mAxis.getOritation() == Axis.Oritation.Horizantal) {
            drawLine(mCanvas, baseLineStartPoint, baseLineStopPoint, mHorizantalBaseLinePaint);
        }else if(mAxis.getOritation() == Axis.Oritation.Vertical) {
            drawLine(mCanvas, baseLineStartPoint, baseLineStopPoint, mVerticalBaseLinePaint);
        }
    }

    /**
     * 绘制标度延长线
     */
    private void drawLines(){

        List<Point> list = mAxis.getDevidePointList();
        for(int i=0; i<list.size(); i++){

            //获取起始点
            Point startPoint = list.get(i);
            //创建结束点
            Point endPoint = new Point();

            if(mAxis.getOritation() == Axis.Oritation.Horizantal){
                //当前为横轴 则刻度线画竖线
                endPoint.x = startPoint.x;
                endPoint.y = 0;
                drawLine(mCanvas, startPoint, endPoint, mHorizantalPaint);
            }else if(mAxis.getOritation() == Axis.Oritation.Vertical){
                //当前为纵轴 则刻度线画横线
                endPoint.x = mAxis.getLineLength();
                endPoint.y = startPoint.y;
                drawLine(mCanvas, startPoint, endPoint, mVerticalPaint);
            }
        }
    }
}
